﻿
//Collector, collects informations from visitor.
LightScript.using("LightScript.Core", function()
{
    var thisClass = LightScript.Core.createClass("LightScript.Collector");

    //# Private Members

    //# Constructions

    //# Public Members
    //Gets parameter value from url.
    //para<String>: param's name.
    //return<String>: the value.
    thisClass.queryString = queryString;
    function queryString(para)
    {
        var loc = document.location.search;
        var reg = new RegExp("(^|&)" + para + "=([^&]*)(&|$)", "i");
        var r = loc.substr(loc.indexOf("\?") + 1).match(reg);

        return r ? r[2] : "";
    }

    thisClass.getBrowser = getBrowser;
    function getBrowser()
    {
        var browser = navigator.userAgent.match(/(Konqueror|Opera|Safar|Firebird|NetCaptor|MSN |Netscape|MSIE|MyIE|OmniWeb|AOL|WebTV|iCab|Maxthon|TencentTraveler|Firefox|GOSURF|America Online Browser|ZoneSurf|Crazy|baidubot|Googlebot|Yahoo|msnbot|Kidzilla|FuckZilla)[\d\/]?\d*\.?\d*\.*\d*[^;\(\)\[]*/gi);
        return browser ? browser.pop() : "other";
    }

    thisClass.getOs = getOs;
    function getOs()
    {
        var os = navigator.userAgent.match(/(Windows|Mac |mac_powerpc|Mac_|Win|PPC|Linux|unix|SunOS|BSD)[^;\(\)\[]{0,20}/gi);
        os = os.toString();
        if (os.search(/Win95/gi) >= 0)
            os = "Windows 95";
        else if (os.search(/Win98/gi) >= 0)
            os = "Windows 98";
        else if (os.search(/Win 9x[\W]*4.90/gi) >= 0)
            os = "Windows Me";
        else if (os.search(/Windows[\W]*(NT)?[\W]*5.0/gi) >= 0)
            os = "Windows 2000";
        else if (os.search(/Windows[\W]*(NT)?[\W]*5.1/gi) >= 0)
            os = "Windows XP";
        else if (os.search(/Windows[\W]*(NT)?[\W]*5.2/gi) >= 0)
            os = "Windows Server 2003";
        else if (os.search(/Windows[\W]*(NT)?[\W]*6.0/gi) >= 0)
            os = "Windows Vista";
        else if (os.search(/Windows[\W]*(NT)?[\W]*6.1/gi) >= 0)
            os = "Windows 7";

        return os;
    }

    thisClass.getKeyFromSE = getKeyFromSE;
    function getKeyFromSE()
    {
        var from = document.referrer;
        var pattern = /(?:baidu.+?(?:w|wd|word)=|google.+?q=|yahoo.+?p=|openfind.+?q=|lycos.+?query=|aol.+?query=|onseek.+?keyword=|search\.tom.+?word=|soso\.com.+?w=|zhongsou\.com.+?word=|msn.+?q=|sohu.+?(?:word|key_word|query)=|sogou.+?query=|163.+?q=|3721\.com.+?(?:name|p)=|Alltheweb.+?q=|sina.+?k=|iask.+k=|alexa.com.+?q=|114.vnet.+?kw=)([^&]*)/i;
        var res = from.match(pattern);

        return res ? res[1] : null;
    }

    //# Private Methods

    //# Public Methods

    //# Shortcuts
});
